<template>
  <div class="strut-div">
    <div class="building-window">
      <div class="building-title">侵占情况分类对比</div>
      <div class="build-main process-box">
        <!-- <div class="num-chart">
          <div class="num-circle">
            <p class="num">
              <coun-to :end="4.03"></coun-to>
            </p>
            <p class="txt">万亩</p>
          </div>
          <div class="arrow-box">
            <img src="@/assets/imgs/tg/arrow-icon.png" alt="arrow" />
          </div>
          <div class="num-circle">
            <p class="num">
              <coun-to :end="1.16"></coun-to>
            </p>
            <p class="txt">万亩</p>
          </div>
          <div class="arrow-box">
            <img src="@/assets/imgs/tg/arrow-icon.png" alt="arrow" />
          </div>
          <div class="num-circle">
            <p class="num">
              <coun-to :end="5.13"></coun-to>
            </p>
            <p class="txt">万亩</p>
          </div>
        </div> -->
        <div class="process-item" v-for="(item,index) in invadeData" :key="index">
          <p class="process-name">{{item.name}}</p>
          <el-progress :text-inside="true" :stroke-width="18" :percentage="item.value" :color="item.color">
          </el-progress>
        </div>
      </div>
    </div>
    <div class="window-item industry-window">
      <div class="window-title">
        <img src="@/assets/imgs/tg/agro-icon.png" alt="menu" />
        基本农田侵占类型对比图
      </div>
      <div class="window-main">
        <common-pieNew-chart ref="rsPlantingAreaPie" :config='rsPlantingAreaPieConfig'></common-pieNew-chart>
      </div>
    </div>
    <div class="window-item economic-window">
      <div class="window-title">
        <img src="@/assets/imgs/tg/agro-icon.png" alt="menu" />
        基本农田年度变化图
      </div>
      <div class="window-main">
        <common-dualarea-chart ref="rsPlantingAreaBar" :config="rsPlantingBarAreaConfig"></common-dualarea-chart>
      </div>
    </div>
  </div>
</template>
<script>
  import {
    mapGetters
  } from "vuex";
  import CounTo from '@/components/count-to';
  import CommonPieNewChart from '@/components/common/common-pieNew-chart.vue';
  import CommonDualareaChart from "@/components/common/common-dualarea-chart.vue";

  export default {
    name: "ng-rs-right",
    components: {
      CounTo,
      CommonPieNewChart,
      CommonDualareaChart
    },
    computed: {
      ...mapGetters(["remote_data"])
    },
    data() {
      return {
        invadeData: [{
            name: '',
            value: 0,
            color: '#0ac3f9'
          }, {
            name: '',
            value: 0,
            color: '#f5ec0b'
          }, {
            name: '',
            value: 0,
            color: '#34f4b9'
        }],
        rsPlantingAreaPieConfig: {
          option: {
            id: 'rsPlantingAreaPie',
            color: ['#7264F7', '#AC4BFC', '#EDA652', '#08C49A', '#19AEF1', '#00EAFF'],
            tooltip: {
              show: true, //防止鼠标移到不需要的数据上弹出label
              trigger: 'item',
              formatter: "{a}{b}:{c}"
            },
            legend: {
              show: true,
              x: "0%",
              y: "bottom",
              orient: 'vertical',
              textStyle: {
                color: ['#7264F7', '#AC4BFC', '#EDA652', '#08C49A', '#19AEF1', '#00EAFF'],
                fontSize: 14,
              },
              padding: 20,
              itemGap: 14,
              data: ["大豆", "水稻", "玉米"]
            },
            series: [{
              name: '',
              type: 'pie',
              radius: 100,
              center: ['50%', '40%'],
              roseType: "radius",
              label: {
                // color: "#fff",
                formatter: '{a} {b}:{d}%',
                fontSize: 16
              },
              labelLine: {
                length: 10,
                length2: 20,
              },
              data: [{
                name: "大豆",
                value: 38
              }, {
                name: "水稻",
                value: 20
              }, {
                name: "玉米",
                value: 12
              }]
            }]
          }
        },
        rsPlantingBarAreaConfig: {
          option: {
            id: "rsPlantingAreaLine",
            x: [],
            y: [{
              axis: {
                min: 0,
                max: null,
                name: "万亩"
              },
              smooth: true,
              title: '',
              data: [],
              startColor: "#40D0A3",
              endColor: "rgba(47,166,179,0.00)"
            }]
          }
        }
      }
    },
    mounted() {
      setTimeout(() => {
        this.initData();
      },2000);
    },
    methods: {
      initData() {
        let _invadeData = this.remote_data.filter(item => item.boxNum == '0106')[0].data;
        _invadeData.forEach((item, index) => {
          this.invadeData[index].name = item.name;
          this.invadeData[index].value = parseInt(item.data[0].value * 100);
        });

        let _plantingAreaPie = this.remote_data.filter(item => item.boxNum == '0105')[0].data.filter(item => item.data
          .length > 0);

        this.rsPlantingAreaPieConfig.option.legend.data = _plantingAreaPie.map(v => v.name);
        this.rsPlantingAreaPieConfig.option.series[0].data = _plantingAreaPie.map(v => {
          return {
            name: v.name,
            value: v.data[0].value
          }
        });

        this.$refs.rsPlantingAreaPie.initChart();

        let _plantingBarArea = this.remote_data.filter(item => item.boxNum == '0107')[0].data;
        this.rsPlantingBarAreaConfig.option.x = _plantingBarArea.map(val => val.data.map(v => v.name));
        _plantingBarArea.forEach((item,index) => {
          this.rsPlantingBarAreaConfig.option.y[index].title = item.name;
          this.rsPlantingBarAreaConfig.option.y[index].data = item.data.map(v => v.value);
        })

        this.$refs.rsPlantingAreaBar.initChart();
      }
    }
  }

</script>
<style lang="scss" scoped>
  .building-window {
    width: 500px;
    height: 270px;
    background: url("../../../assets/imgs/tg/leftop-window.png") no-repeat center center;
    background-size: 100% 100%;
    float: left;

    .building-title {
      width: 100%;
      height: 68px;
      line-height: 68px;
      padding-left: 10px;
      font-size: 22px;
      color: #aaddff;
    }

    .build-main {
      .num-chart {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 26px 0 62px;

        .num-circle {
          display: flex;
          justify-content: center;
          align-items: center;
          flex-direction: column;
          width: 96px;
          height: 96px;
          background: url("../../../assets/imgs/tg/circle-bg.png");

          .num {
            font-size: 18px;
            font-weight: bold;
            color: #f7cc49;
          }

          .txt {
            font-size: 10px;
            color: #aaddff;
          }
        }
      }

      .desc-box {
        height: 100px;

        .desc-txt {
          width: 94px;
          font-size: 20px;
          color: #aaddff;
          text-align: center;
        }

        @extend .num-chart
      }
    }
  }

  .window-item {
    width: 470px;
    background: url("../../../assets/imgs/tg/chart-window-v2.png") no-repeat;
    background-size: 100% 100%;

    .window-title {
      height: 70px;
      line-height: 70px;
      font-size: 22px;
      color: #aaddff;
      padding-left: 20px;

      >img {
        vertical-align: middle;
      }
    }

    .window-main {
      height: calc(100% - 70px);
    }
  }

  .industry-window {
    height: 380px;
    float: left;
    margin-top: 20px;
    margin-left: 28px;
  }

  .economic-window {
    height: 300px;
    float: left;
    margin-top: 20px;
    margin-left: 28px;
  }

  .process-box {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: 200px;

    .process-item {
      padding: 0 30px 0 45px;

      .process-name {
        color: #0bc3f5;
      }
      ::v-deep .el-progress-bar__outer {
        background-color: transparent;
        border: 1px solid #0bc3f5;
      }
    }
  }

</style>
